package test;

import java.util.Comparator;

public class MyComparable implements Comparator {
    @Override
    public int compare(Object o1, Object o2) {
        if (!(o1 instanceof String) && !(o2 instanceof String)){
           throw new RuntimeException("比较的是字符串");
        }
        String o11 = (String) o1;
        String o22 = (String) o2;
        int i = o11.length() - o22.length();
        return i;
    }
}
